<?php

namespace app\common\model;

use think\Image;
use think\Model;

class MemberToken extends Model
{



    protected $autoWriteTimestamp = true;

    private $error_code = 40001;

    private $error_msg = 'token无效';
    //
    public function getErrorCode()
    {
        return $this->error_code;
    }
    public function getErrorMsg()
    {
        return $this->error_msg;
    }

    /**
     * 根据token获取uid
     * @param  [type] $token [description]
     * @return [type]        [description]
     */
    public function getUidByToken($token)
    {

        //被顶号的错误码
        $detail=$this->where(['access_token'=>$token])->find();

        if ($detail['expired_time'] < time()){
            $this->error_msg = 'token已过期';
            return false;
        }
        return $detail['uid'] ? $detail['uid'] : false;
    }

}
